Minor changes
[matilda.git] / docs / SGF Spec / var.htm
blob8986611e34416ffd7e6c88fb2a43897a14726a39
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML>
3 <HEAD><TITLE>SGF - Variations</TITLE>
4 </HEAD>
5 <BODY alink="#FF0000" bgcolor="#FFFFFF" link="#0000FF" text="#000000" vlink="#FF0000">
6 <A HREF="index.html"><IMG src="images/head.gif" ALT="[SGF FF[4] - Smart Game Format]" BORDER=0></A> <I>last updated: 1999-01-07</I>
8 <H1><A NAME="4">Variations</A></H1>
10 SGF's internal structure is a tree of property lists.
11 This allows storing variations of the main line of play.
12 The tree is written in pre-order.
13 Here's a short sketch for an algorithm for writing a tree in pre-order:
14 <P>
15 <TABLE BORDER=1>
16 <TR><TD BGCOLOR="#ff0000"><FONT COLOR=white>Algorithm</FONT>
17 <TD BGCOLOR="#ff0000"><FONT COLOR=white>Example tree</FONT>
18 <TD BGCOLOR="#ff0000"><FONT COLOR=white>pre-order</FONT>
19 <TR><TD ROWSPAN=3>
20 <PRE>
21 WriteTree(Root)
22 End
24 WriteTree(Node)
25 Write(Node)
26 for each child of Node
27 WriteTree(child)
28 end for
29 end
30 </PRE>
31 <TD ROWSPAN=3><IMG src="images/TA1.gif" ALT="[ node-tree ]">
32 <TD>root a b c d e f g h i j
33 <TR><TD BGCOLOR="#ff0000"><FONT COLOR=white>SGF</FONT>
34 <TR><TD><PRE>(;FF[4]C[root](;C[a];C[b](;C[c])
35 (;C[d];C[e]))
36 (;C[f](;C[g];C[h];C[i])
37 (;C[j])))
38 </PRE>
39 </TABLE>
40 <P>
41 Have a look at the <A HREF="sgf4.html#ebnf-def">EBNF definition</A>
42 again. Check the <A HREF="examples">SGF example file</A> and the
43 <A HREF="user_guide">User Guide</A> for more details, such as
44 problems with annotations and variations. Related properties:
45 <A HREF="properties.html#ST">ST</A>, <A HREF="properties.html#C">C</A>,
46 <A HREF="properties.html#N">N</A>.
47 <P>
48 Here are some examples to make it easier to understand the
49 EBNF definition and its application to variations.
50 <BR><SMALL>Pictures taken from cgoban</SMALL>
51 <P>
53 <TABLE BORDER=1>
54 <TR><TD ROWSPAN=2 BGCOLOR="#efefff">No Variation
55 <TD><IMG src="images/var1.gif" ALT="[ no variations ]">
56 <TR><TD><PRE>(;FF[4]GM[1]SZ[19];B[aa];W[bb];B[cc];W[dd];B[ad];W[bd])</PRE>
58 <TR><TD ROWSPAN=3 BGCOLOR="#efffff">One variation at move 3
59 <TD><IMG src="images/var2.gif" ALT="[ one variation ]">
60 <TR><TD><PRE>(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc];W[dd];B[ad];W[bd])
61 (;B[hh];W[hg]))</PRE>
62 <TR><TD>Note the beginning of a new game tree in front of <TT>B[cc]</TT>
63 and the variation itself on the second line. There are two ")" at the end:
64 one for the variation gametree and one for the end of the main gametree
65 starting at <TT>FF[4]</TT>.
67 <TR><TD ROWSPAN=3 BGCOLOR="#efefff">Two variations at move 3
68 <TD><IMG src="images/var3.gif" ALT="[ two variations ]">
69 <TR><TD><PRE>(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc]N[Var A];W[dd];B[ad];W[bd])
70 (;B[hh]N[Var B];W[hg])
71 (;B[gg]N[Var C];W[gh];B[hh];W[hg];B[kk]))</PRE>
72 <TR><TD>Usually the main line is labeled variation "A", the first variation
73 "B", the second variation "C" and so on. That's why many annotations refer
74 to the next move as "A".
76 <TR><TD ROWSPAN=3 BGCOLOR="#efffff">Two variations at different moves
77 <TD><IMG src="images/var4.gif" ALT="[ one and one variation ]">
78 <TR><TD><PRE>(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc];W[dd](;B[ad];W[bd])
79 (;B[ee];W[ff]))
80 (;B[hh];W[hg]))</PRE>
81 <TR><TD>The new gametree starts in front of <TT>B[ad]</TT>. Note that
82 the second varition (2nd line) is in front of the first variation (3rd line).
83 Have a look at the closing brackets as well.
85 <TR><TD ROWSPAN=3 BGCOLOR="#efefff">Variation of a variation
86 <TD><IMG src="images/var5.gif" ALT="[ variation of variation ]">
87 <TR><TD><PRE>(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc]N[Var A];W[dd];B[ad];W[bd])
88 (;B[hh]N[Var B];W[hg])
89 (;B[gg]N[Var C];W[gh];B[hh] (;W[hg]N[Var A];B[kk]) (;W[kl]N[Var B])))</PRE>
90 <TR><TD>The new game tree starts in front of <TT>W[hg]</TT>. Note that
91 there are three ")" at the end: one for the <TT>W[kl]</TT> variation, one
92 for the <TT>B[gg]</TT> variation, and one for the main gametree.
93 </TABLE>
95 <P>
96 <H2>Common pitfalls:</H2>
97 Every variation has at least one node (see <A HREF="sgf4.html#ebnf-def">EBNF
98 definition</A>)! That is, the smallest possible variation looks like
99 <TT>(;)</TT> - <TT>()</TT> is an error! Another example: removing all
100 properties from the "variation of a variation" example leads to:
101 <TT>(;;;(;;;;)(;;)(;;;(;;)(;)))</TT> and additionally removing unnecessary
102 nodes leads to <TT>(;(;)(;)(;(;)(;)))</TT>
104 Properties are part of a node, therefore <TT>(W[tt])</TT> is an error.
105 Correct is <TT>(<B>;</B>W[tt])</TT>
107 No properties outside a gametree! E.g. <TT>(;)W[tt]</TT> is an error.
109 </BODY></HTML>